package DatabaseCommands;

import java.sql.DriverManager;
import java.sql.SQLException;
import Code.SSHTunnel;
import Code.Window;


public class Connect{
	
	DatabaseInfo DInfo=DatabaseInfo.getInstance();
	Window W=Window.getInstance();
	
	
	public Connect(String Address,String DatabaseAddress,String User,String Password,int SSHPort,int LocalPort,int RemotePort){
		try{
			new SSHTunnel().Connect(Address,DatabaseAddress,User,Password,SSHPort,LocalPort,RemotePort);
		}catch(Exception e){
			System.out.println("SSH Connect Error");
			return;
		}
		DBConnect();
	}
	
	
	
	public Connect(){
		
		DBConnect();
	}
	
	
	public boolean DBConnect(){
		
		ActivateDriver();
		
		try{
			DInfo.ConnectToDataBase();
		}catch(Exception e){
			System.out.println("Database Connect Error");
			return false;
		}
		
		W.SwitchToDatabaseHome();
		return false;
	}
	
	
	public boolean ActivateDriver(){
		try{
			DriverManager.registerDriver(new com.mysql.jdbc.Driver());
		}catch (SQLException sqle){
			sqle.printStackTrace();
		}
		return true;
	}

	

}
